home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et3_0-a1.lha / et3 / src / GraphView.h < prev    next >
C/C++ Source or Header  |  1992-05-13  |  4KB  |  145 lines

  1. #ifndef GraphView_First
  2. #ifdef __GNUG__
  3. //pragma once
  4. #pragma interface
  5. #endif
  6. #define GraphView_First
  7.  
  8. #include "TreeView.h"
  9. #include "Collection.h"
  10.  
  11. //---- GraphNode ------------------------------------------------------------------
  12.  
  13. enum GraphNodeFlags {
  14.     eGraphPosSet        =   BIT(eTreeNodeLast+1),
  15.     eGraphInCalc        =   BIT(eTreeNodeLast+2),
  16.     eGraphNodeLast      =   eTreeNodeLast+2
  17. };
  18.  
  19. class GraphNode: public TreeNode {
  20.     Collection *constrainingNodes;
  21.     Collection *nonTreeOutEdges;
  22.     int inEdges;
  23. public:
  24.     MetaDef(GraphNode);
  25.  
  26.     GraphNode(int id= cIdNone, Collection *cp= 0);
  27.     ~GraphNode();
  28.     
  29.     //---- construction
  30.     void AddNonTreeOutEdge(GraphNode*);
  31.     void AddConstrainingNode(GraphNode*);
  32.     void AddNode(VObject *vp);
  33.     void AddInEdge(VObject *)
  34.     { inEdges++; }
  35.     int NumInEdges()
  36.     { return inEdges; }
  37.     
  38.     //---- layout
  39.     int CalcShift();   
  40.     // calculate amout to shift a node to the right
  41.     bool InCalcShift()
  42.     { return TestFlag(eGraphInCalc); }
  43.     bool IsPositionSet()
  44.     { return TestFlag(eGraphPosSet); }
  45.     VObject *Image();
  46.     
  47.     //---- drawing
  48.     void Draw(Rectangle);
  49.     void DrawConnections();
  50.  
  51.     //---- input/output
  52.     void Export(OStream &s);
  53. };
  54.  
  55. //---- GraphView ----------------------------------------------------------------
  56.  
  57. class GraphView: public TreeView {
  58.     class Collection *paths, *refs;
  59.  
  60. protected:    
  61.     class IdDictionary *nodes;      // maps objects to GraphNodes
  62.     void DrawPaths(Rectangle r);
  63.     void DrawReferences(Rectangle r);
  64.     GraphNode* GraphNodeAtKey(Object *op);
  65.  
  66.     VObject *DoCreateDialog();
  67.     Iterator *MakeChildrenIter(Object *op);
  68.     
  69. public:
  70.     MetaDef(GraphView);
  71.     GraphView(EvtHandler *dp);
  72.     ~GraphView();
  73.     
  74.     //---- construction 
  75.     void EmptyGraph();
  76.     GraphNode *BuildGraphDFS(Object *);
  77.     void BuildGraphBFS(Object *);
  78.     GraphNode *FindRoot();
  79.     void SetGraph(GraphNode *root, bool free=TRUE);
  80.     void CalcExtent();
  81.     
  82.     //---- hooks for BuildGraph/FindRoot
  83.     virtual VObject *DoCreateRoot();
  84.     virtual Iterator *MakeSubPartsIter(Object *);
  85.     
  86.     //---- drawing
  87.     void SetConnType(TreeConnection ct);
  88.     void Draw(Rectangle);
  89.  
  90.     //---- accessing
  91.     VObject *AssociatedVObject(Object *);
  92.     GraphNode *AssociatedGraphNode(Object *);
  93.     GraphNode *FindNode(Point p);
  94.     
  95.     Command *DoLeftButtonDownCommand(Point lp, Token t, int cl);
  96.     Command *DoMiddleButtonDownCommand(Point lp, Token t, int cl);
  97.  
  98.     //---- path handling 
  99.     void AddPath(class GraphPath*);
  100.     GraphPath *RemovePath(class GraphPath*);
  101.     void RemoveAllPaths();
  102.  
  103.     //---- references handling
  104.     void AddReference(class GraphReference*);
  105.     GraphReference *RemoveReference(GraphReference*);
  106.     void RemoveAllReferences();
  107. };
  108.  
  109. //---- GraphPath ------------------------------------------------------------
  110.  
  111. class GraphPath: public VObject {
  112.     class Collection *nodes;
  113.     GraphView *gvp;
  114.     int width;
  115.     Ink *ink;
  116.     bool free;
  117. public:
  118.     GraphPath(GraphView *, Collection *nodes, Ink *ink, int width= 2, bool free= FALSE);
  119.     ~GraphPath();
  120.     void Draw(Rectangle);
  121.     Rectangle BBox();
  122. };
  123.     
  124. //---- GraphReference ------------------------------------------------------------
  125.  
  126. class GraphReference: public VObject {
  127. protected:
  128.     class Collection *nodes;
  129.     Object *referto;
  130.     GraphView *gvp;
  131.     int width;
  132.     Ink *ink;
  133.     bool free;
  134. public:
  135.     GraphReference(GraphView *, Object *op, Collection *nodes, Ink *ink, int width= 2, bool free= FALSE);
  136.     ~GraphReference();
  137.     virtual void Draw(Rectangle);
  138.     virtual void DrawConnection(int n, VObject *from, VObject *to);
  139.     Rectangle BBox();
  140. };
  141.  
  142. #endif
  143.  
  144.  
  145.